<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>date</title>
</head>
<body>
  <span>请输入时间戳:</span>
  <input type="text" id="text">
  <button id="sure">确认</button>
  <span>结果:</span>
  <span id="result"></span>
  <script >
    window.onload=function(){
        let sure = document.getElementById("sure")
        sure.onclick=function(){
          let aaa = document.getElementById("text")
          let  bbbRes= document.getElementById("result")
          if(!isNaN(parseInt(aaa.value))){
            if(aaa.value.length >= 10|| aaa.value.length <= 13){
              bbbRes.innerHTML = get(Number(aaa.value))
            }else{
              alert("输入的字符串长度不符!")
            }
          }else{
            alert("输入的数据必须是时间戳格式!")
          }
        }
    function get(today) {
        let year = new Date(today).getFullYear()
        let month = new Date(today).getMonth()+1
        let day = new Date(today).getDate()
        let hour = new Date(today).getHours()
        let minute = new Date(today).getMinutes()
        let sec = new Date(today).getSeconds()
        return sumrize(year) + "/" + sumrize(month) + "/" + sumrize(day) + " " + sumrize(hour) + ":" + sumrize(minute) + ":" + sumrize(sec)
       
    }
    function sumrize(today){
     return today >= 10 ? today : "0" +today
    }
  }
    </script>
</body>
</html>